#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/TermStructure.h>
#pragma unmanaged 
#include <ql\experimental\commodities\commoditycurve.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL;
using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Experimental { namespace Commodities {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ICommodityCurve
	public ref class CCommodityCurve  : 
            public CTermStructure,
            public Cephei::QL::Experimental::Commodities::ICommodityCurve
	{
	protected: 
		boost::shared_ptr<QuantLib::CommodityCurve>* _ppCommodityCurve;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CommodityCurve>* _phCommodityCurve;
#endif
		Object^ _CommodityCurveOwner;     // reference to object that manages the storage for this object
	internal:
		CCommodityCurve (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter);
		CCommodityCurve (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Cephei::Core::IVector<DateTime>^ dates, Cephei::Core::IVector<Double>^ prices, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter);
        CCommodityCurve (boost::shared_ptr<QuantLib::CommodityCurve>& childNative, Object^ owner);
        CCommodityCurve (QuantLib::CommodityCurve& childNative, Object^ owner);
        CCommodityCurve (CCommodityCurve^ copy);
        CCommodityCurve (PLATFORM::Type^ t);
#ifdef STRUCT
        CCommodityCurve (QuantLib::CommodityCurve childNative);
#endif       
#ifdef HANDLE
		CCommodityCurve (QuantLib::Handle<QuantLib::CommodityCurve>& childNative, Object^ owner);
		CCommodityCurve (QuantLib::Handle<QuantLib::CommodityCurve> childNative);
#endif
		virtual ~CCommodityCurve ();
		!CCommodityCurve ();

	internal:
		QuantLib::CommodityCurve& GetReference ();
		boost::shared_ptr<QuantLib::CommodityCurve>& GetShared ();
		QuantLib::CommodityCurve* GetPointer ();
        void SetCommodityCurve (boost::shared_ptr<QuantLib::CommodityCurve> native)
        {
            if (_ppCommodityCurve != NULL)
                delete _ppCommodityCurve;
            _ppCommodityCurve = new boost::shared_ptr<QuantLib::CommodityCurve> (native);
            SetTermStructure (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppCommodityCurve));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::CommodityCurve>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::QL::Experimental::Commodities::ICommodityCurve^ BasisOfCurve 
        {
		    virtual Cephei::QL::Experimental::Commodities::ICommodityCurve^ get () ;
        }
		virtual Double BasisOfPrice (DateTime d) ;
        property Cephei::QL::Experimental::Commodities::ICommodityType^ CommodityType 
        {
		    virtual Cephei::QL::Experimental::Commodities::ICommodityType^ get () ;
        }
        property Cephei::QL::ICurrency^ Currency 
        {
		    virtual Cephei::QL::ICurrency^ get () ;
        }
        property Cephei::Core::IVector<DateTime>^ Dates 
        {
		    virtual Cephei::Core::IVector<DateTime>^ get () ;
        }
        property Boolean Empty 
        {
		    virtual Boolean get () ;
        }
        property DateTime MaxDate 
        {
		    virtual DateTime get () ;
        }
        property String^ Name 
        {
		    virtual String^ get () ;
        }
        property Cephei::Core::IVector<Double>^ Prices 
        {
		    virtual Cephei::Core::IVector<Double>^ get () ;
        }
		virtual Cephei::QL::Experimental::Commodities::ICommodityCurve^ SetBasisOfCurve (Cephei::QL::Experimental::Commodities::ICommodityCurve^ basisOfCurve) ;
        property Cephei::Core::IVector<Double>^ Times 
        {
		    virtual Cephei::Core::IVector<Double>^ get () ;
        }
        property Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ UnitOfMeasure 
        {
		    virtual Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Experimental::Commodities::ICommodityCurve^>::typeid)]
	[FactoryFor(Cephei::QL::Experimental::Commodities::ICommodityCurve::typeid)]
	[FactoryFor(Cephei::QL::Experimental::Commodities::ICommodityCurve_Factory::typeid)]
	public ref class CCommodityCurve_Factory sealed : public ICommodityCurve_Factory
	{
	public:
        virtual ICommodityCurve^ Create (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter);
        virtual ICommodityCurve^ Create (String^ name, Cephei::QL::Experimental::Commodities::ICommodityType^ commodityType, Cephei::QL::ICurrency^ currency, Cephei::QL::Experimental::Commodities::IUnitOfMeasure^ unitOfMeasure, Cephei::QL::Times::ICalendar^ calendar, Cephei::Core::IVector<DateTime>^ dates, Cephei::Core::IVector<Double>^ prices, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dayCounter);
    };
   
/*Cephei*/ } /*QL*/ } /*Experimental*/ } /*Commodities */}
